package com.ciaojian.client.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ciaojian.client.service.ChargeLogServiceImpl;
import com.ciaojian.client.service.ChargeServiceImpl;
import com.ciaojian.client.service.ChargeUserServiceImpl;
import com.ciaojian.client.service.OrderServiceImpl;
import com.ciaojian.core.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * @author oxiny
 */
@Api(tags = "卡金模块")
@RestController
@RequestMapping("/charge")
public class ChargeController {
    @Resource
    private ChargeServiceImpl chargeService;
    @Resource
    private ChargeUserServiceImpl chargeUserService;
    @Resource
    private ChargeLogServiceImpl chargeLogService;
    @Resource
    private OrderServiceImpl orderService;

    @ApiOperation("分页查询")
    @GetMapping
    public Result page(@NotNull(message = "userType must be not null") Integer userType,
                       @RequestParam(defaultValue = "0") Integer pageNo,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.ok(chargeService.page(userType, 1, new Page<>(pageNo, pageSize)));
    }

    @ApiOperation("卡金流水记录")
    @GetMapping("/log")
    public Result pageChargeLog(@NotNull(message = "userId must be not null") Integer userId,
                                @RequestParam(defaultValue = "0") Integer pageNo,
                                @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.ok(chargeLogService.pageCharge(userId, new Page<>(pageNo, pageSize)));
    }

    @ApiOperation("卡金充值详情")
    @GetMapping("/order/{orderId}")
    public Result getChargeOrder(@PathVariable Integer orderId) {
        return Result.ok(orderService.getChargeOrder(orderId));
    }

    @ApiOperation("查询用户卡金余额")
    @GetMapping("/charge/user/balance")
    public Result getBalance(Integer userId) {
        return Result.ok(chargeUserService.getBalance(userId));
    }



}
